package realQuestion.tuan;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] weights = new int[n];

        for (int i = 0; i < n; i++) {
            weights[i]=scanner.nextInt();
        }

        List<List<Integer>> graph = new ArrayList<>();
        for (int i = 0; i <n ; i++) {
            graph.add(new ArrayList<>());
        }

        for (int i = 0; i <n-1; i++) {
            int u=scanner.nextInt()-1;
            int v=scanner.nextInt()-1;
            graph.get(u).add(v);
            graph.get(v).add(u);
        }
        int[]  visited=new int[n];
        int[] count = new int[1];
        dfs(graph,weights,visited,count,0);
        System.out.println(count[0]);
    }

    static  void  dfs(List<List<Integer>> graphs,int[] weights,int[]  visited,int[] count,int node){
        visited[node]=1;
        int product=(int )Math.sqrt(weights[node]);
        if (product*product==weights[node]){
            count[0]++;
        }
        for (int neighbor :
                graphs.get(node)) {
if (visited[neighbor]==0){
    dfs(graphs,weights,visited,count,neighbor);
}
        }
    }

}
